package cn.kmsoft.jssc.service;

import cn.kmsoft.common.utils.StringUtil;
import cn.kmsoft.jssc.config.AnalyseConfig;
import cn.kmsoft.jssc.entity.analyse.*;
import cn.kmsoft.jssc.service.processor.*;
import cn.kmsoft.stgeometry.util.JTSGeometryWKTUtil;
import cn.kmsoft.wololo.object.GeoJson;
import cn.kmsoft.wololo.object.GeoJsonFeature;
import cn.kmsoft.wololo.object.GeoJsonGeometry;
import cn.kmsoft.wololo.object.query.GeoJsonQuery;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.JsonObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;
import java.util.concurrent.*;

@Service
public class ParallelAnalyseService {
    private static final Logger logger = LoggerFactory.getLogger(ParallelAnalyseService.class);

    //面积变换缩放比例，平方米与公顷
    private final double areaScale = 10000;

    //线程池大小或者线程个数
    private final int fixMaxThreadTaskSizeByDK = 15;
    private final int fixMaxThreadTaskSizeByAnalyseTables = 10;

    //规划调整
    private final int ghtzThreadTaskSize = 5;
    private final int tzhThreadTaskSize = 2;
    //基本农田占用
    private final int jbntZyThreadTaskSize=2;
    //基本农田补划
    private final int jbntBhThreadTaskSize=3;
    private final int jbntBhThreadTaskSizeEx=2;
    //非单选项目审查
    private final int fdxxmThreadTaskSize = 6;
    //建设用地剩余量计算
    private final int jsydSylThreadTaskSize = 1;
    //规划调整备案
    private final int ghtzBAThreadTaskSize = 1;

    @Autowired
    private AnalyseConfig analyseConfig;


    /**
     * 直接使用区县上报的Shp图层进行分析（转换)
     *
     * 主要是为了实现2009年以前地类还原分析
     *
     * @param analyseType
     * @param taskParam
     * @return
     */
    public CustomOverlay doDirectGeoJsonQueryConvert(String analyseType, GeoJsonQuery geoJsonQuery, AnalyseTaskParam taskParam){
        String dkbh = taskParam.getDkbh();
        String jobId = taskParam.getJobId();
        String taskId= taskParam.getTaskId();
        //double dkmj = param.getDkmj();
        String msg = String.format("--->doDirectGeoJsonQueryConvert start, analyseType: %s,jobid: %s,  dkbh: %s",analyseType, jobId, dkbh);
        System.out.println(msg);
        logger.info(msg);

        CustomOverlay result = new CustomOverlay();
        result.setTaskId(taskId);
        result.setDkbh(dkbh);
        result.setJobId(jobId);
        result.setDkmj(taskParam.getDkmj());
        result.setNf(taskParam.getDlhynf());//数据年份

        Map<String, List<DetailResult>> overlays_details = new HashMap<String, List<DetailResult>>();
        String geoJsonStr = geoJsonQuery.getGeoJson();
        GeoJson dkGeoJson = JSONObject.parseObject(geoJsonStr,GeoJson.class);

        List<DetailResult> detailResultList = new ArrayList<DetailResult>();

        List<GeoJsonFeature> features = dkGeoJson.getFeatures();
        for (int i=0;i<features.size(); i++) {
            GeoJsonFeature fea = features.get(i);

            Map<String, Object> feaProperties = fea.getProperties();
            //将要素属性的key全部转为小写，否则oracle和postgresql数据库返回的结果会有差异
            Map<String,Object> feaPropsKeyLowercCase = new HashMap<>();
            feaProperties.forEach((key,value) -> feaPropsKeyLowercCase.put(key.toLowerCase(), value));

            /*
            System.out.println();
            System.out.println(String.format("--->第%d 个要素",i+1));
            Set<String> propKeySet = fea.getProperties().keySet();
            for (String propKey: propKeySet){
                String propVal= fea.getProperties().get(propKey ).toString();
                System.out.println(String.format("--->propKey:%s, propVal: %s",propKey,propVal));
            }
            */

            //1-属性
            String tbbh = feaPropsKeyLowercCase.get("tbbh").toString();//TBBH
            String dldm = feaPropsKeyLowercCase.get("dlbm").toString();//DLBM
            String dlmc = feaPropsKeyLowercCase.get("dlmc").toString();//DLMC
            String bhdm = feaPropsKeyLowercCase.get("bhdm").toString();//BHDM
            String hysjnd2 = feaPropsKeyLowercCase.get("hysjnd2").toString();//年份1997-HYSJND2
            String qsdlmc = feaPropsKeyLowercCase.get("qsdwmc").toString();//QSDWMC
            Double djmj = StringUtil.parseDouble(feaPropsKeyLowercCase.get("djmj").toString(),"0.0");//DJMJ

            //耕地
            if(analyseConfig.getTdlyfldmConfig().getTdlyxzfldm_gd().contains(dldm) || analyseConfig.getTdlyfldmConfig().getTdlyxzfldm_gd_sd().contains(dldm)){
                String  msgStr = String.format("---> 直接使用区县上传的地类图斑成果无法计算田坎面积，行政乡镇-村社: %s, 图斑编号: %s ,地类名称: %s, 年份: %s, 面积: %f，",qsdlmc,tbbh, dlmc,hysjnd2,djmj);
                System.out.println(msgStr);
                logger.info(msgStr);
            }

            //2-图形
            GeoJsonGeometry geoJsonGeom = fea.getGeometry();
            String geomStr = JSON.toJSONString(geoJsonGeom);

            DetailResult detailResult = new DetailResult();
            detailResult.setTbbh(tbbh);
            detailResult.setBm(dldm);
            detailResult.setMc(dlmc);
            //没法计算耕地的田坎面积
            detailResult.setArea(djmj);
            detailResult.setSgeoarea(djmj);
            detailResult.setFgeoarea(djmj);
            detailResult.setKcarea(0);
            detailResult.setTkarea(0);
            detailResult.setTkxs(0);
            detailResult.setKcharea(djmj);
            //2-图形
            detailResult.setGeojson(geoJsonStr);
            detailResult.setGeomText(geomStr);

            //System.out.println(JSONObject.toJSONString(detailResult));
            detailResultList.add(detailResult);
        }
        String key = "dltb"+"-"+"qx_dltb_lt2000";
        overlays_details.put(key,detailResultList);

        result.setOverlays_details(overlays_details);

        return result;
    }

    /**
     * 空间叠加套合分析，以不同目标表为单位开展多线程并行运算
     *
     * 项目红线分别与多年的变更调查（2009-2019）、规划地类、基本农田、管制区等进行空间叠加分析
     * @param param  用于多线程任务分析的参数
     * @param analyseTables  待分析的对象表集合
     * @return
     */
    public CustomOverlay submitOverlayCustomAnalyse(String analyseType, TaskParam param, List<AnalyseTable> analyseTables) {
        System.out.println();
        String jobId = param.getJobId();
        String dkbh = param.getDkbh();
        String taskId= param.getTaskId();
        //double dkmj = param.getDkmj();
        String msg = String.format("--->submitOverlayCustomAnalyse start, analyseType: %s, jobid: %s, dkbh: %s",analyseType, jobId, dkbh);
        System.out.println(msg);
        logger.info(msg);

        CustomOverlay result = new CustomOverlay();
        result.setTaskId(taskId);
        result.setDkbh(dkbh);
        result.setJobId(jobId);
        result.setDkmj(param.getDkmj());
        result.setNf(param.getDlhynf());//数据年份

        int wkid = param.getWkid();
        Map<String, Map<String, Statis03Result>> overlays_statis = new HashMap<String, Map<String,Statis03Result>>();
        Map<String, List<DetailResult>> overlays_details = new HashMap<String, List<DetailResult>>();

        //核心代码，构建Java的多线程计算完成服务
        int sizeOfAnalyseTable = analyseTables.size();//待分析目标数据表的数量
        int maxThreadTaskSize = sizeOfAnalyseTable * 2 + 1;
        //ExecutorService threadPool = Executors.newCachedThreadPool();
        ExecutorService threadPool = Executors.newFixedThreadPool(maxThreadTaskSize);

        // 构建N个生成者
        // 提交线程并行处理，整合Executor和BlockingQueue的功
        CompletionService<TaskResult> completionService = new ExecutorCompletionService<TaskResult>(threadPool);

        //逐个数据类型表AnalyseTable，提交线程分析
        int sizeOfSubmmitThread=0;//提交的线程数
        Iterator<AnalyseTable> analyseTableIterator = analyseTables.iterator();
        while(analyseTableIterator.hasNext()) {
            AnalyseTable analyseTable = analyseTableIterator.next();

            System.out.println();

            //数据库表名
            String tableName = analyseTable.getTableName();//数据库的数据表表名
            String tableLabel = analyseTable.getTableLabel();
            String analysePointCode = analyseTable.getAnalysePoint().toLowerCase();//dltb、STBHHX、YJJBNT
            String typepoint = analyseTable.getTypepoint();//py、py2
            String dbKey = analyseTable.getDbKey();//sde、pg
            int fgeo_wkid = analyseTable.getWkid();//投影坐标EPSG代码
            int mbsjnf = param.getDlhynf();//目标数据年份

            //若上传的图形wkid和目标图层的fgeo_wkid相同，则强制采用pt/pl/py;否则采用pt/pl/py
            if(fgeo_wkid==wkid){
                typepoint= typepoint.substring(0,2);
            }

            System.out.println(String.format("--->submit processor, analysePoint: %s, tableName: %s, mbsjnf: %d ",analysePointCode, tableName, mbsjnf));

            //核心参数
            String dar1[] = analysePointCode.split("_");
            if( dar1.length >1 ){
                analysePointCode = dar1[1];//分析点
            }

            //2023-12-18 wangq
            //通过analystpoint匹配到对应的Processor处理器中
            String processorName = analysePointCode;
            List<AnalysePoint> analysePoints = analyseConfig.getAnalysePoints();
            for (AnalysePoint analysePoint: analysePoints) {
                if(analysePoint.getCode().equalsIgnoreCase(analysePointCode)){
                    processorName = analysePoint.getProcessor();
                    break;
                }
            }

            AnalyseTaskParam taskParam = new AnalyseTaskParam(param, typepoint, tableName);
            taskParam.setAnalystType(analyseType);
            taskParam.setDlhynf(mbsjnf);
            taskParam.setFgeo_wkid(fgeo_wkid);//设置目标图层的wkid
            taskParam.setDbKey(dbKey); //目标图层所在db
            taskParam.setAnalysePoint(analysePointCode);
            taskParam.setProcessName(processorName);

            AnalyseTaskProcessor taskProcessor = null;
            if("dltb".equals(processorName)) {
                if(param.getDlhynf()==0){
                    mbsjnf = StringUtil.parseInt(analyseTable.getYear(),"2021");//目标数据年份字符串
                    taskParam.setDlhynf(mbsjnf);//数据年份
                }
                taskProcessor = new DltbAnalyseTaskProcessor(taskParam,this.analyseConfig);
            }else if("yjjbnt".equals(processorName)){
                taskProcessor = new YjjbntAnalyseTaskProcessor(taskParam,this.analyseConfig);
            }else if("stbhhx".equals(processorName)){
                taskProcessor = new StbhhxAnalyseTaskProcessor(taskParam,this.analyseConfig);
            } else if("czkfbj".equals(processorName)){
                taskProcessor = new CzkfbjAnalyseTaskProcessor(taskParam,this.analyseConfig);
            } else if("tdghdl".equals(processorName)){
                taskProcessor = new TdghdlAnalyseTaskProcessor(taskParam,this.analyseConfig);
            } else if("jsydgzq".equals(processorName)){
                taskProcessor = new JsydgzqAnalyseTaskProcessor(taskParam,this.analyseConfig);
            } else if("csgh-kg".equals(processorName)){
                taskProcessor = new KgAnalyseTaskProcessor(taskParam,this.analyseConfig);
            } else if("cgjc".equals(processorName)){
                taskProcessor = new CgjcAnalyseTaskProcessor(taskParam,this.analyseConfig);
            }else if("common".equals(processorName)){
                taskProcessor = new CommonAnalyseTaskProcessor(taskParam,this.analyseConfig);
            }
            else {
                System.out.println("--->submitOverlayCustomAnalyse abandom, tableName is not fit to analsytPoint rules");
            }

            if(taskProcessor !=null) {
                //提交请求
                completionService.submit(taskProcessor);
                sizeOfSubmmitThread++;
            }
        }

        try {
            //主线程等待0.5秒
            Thread.sleep(500);
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }


        //利用主线程作为一个消费者
        for(int i=0; i<sizeOfSubmmitThread; i++) {
            try {
                //阻塞获取
                Future<TaskResult> ft = completionService.take();
                TaskResult taskResult = null;
                if(ft != null ) {
                    try {
                        //最长等待3秒
                        taskResult = ft.get(3000, TimeUnit.MILLISECONDS);
                        //res = ft.get();
                    }
                    catch(InterruptedException e) {
                        e.printStackTrace();
                    }
                    catch (TimeoutException e) {
                    	e.printStackTrace();
                    }

                    if(taskResult == null) {
                        continue;
                    }

                    this.threadAfterHandler(result, taskResult, overlays_statis, overlays_details );
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
        threadPool.shutdown();

        result.setOverlays_statis(overlays_statis);
        result.setOverlays_details(overlays_details);

        System.out.println(String.format("--->submitOverlayCustomAnalyse finished, analyseType: %s, jobid: %s, dkbh: %s",analyseType, jobId, dkbh));


        return result;
    }

    /**
     * 空间叠加套合分析，以不同目标表为单位开展多线程并行运算
     *
     * 项目红线分别与多年的变更调查（2009-2019）、规划地类、基本农田、管制区等进行空间叠加分析
     * @param param  用于多线程任务分析的参数
     * @param analyseTables  待分析的对象表集合
     * @return
     */
    public CustomOverlay submitOverlayCustomAnalyseEx(String analyseType, TaskParam param, List<AnalyseTable> analyseTables) {
        System.out.println();
        String jobId = param.getJobId();
        String dkbh = param.getDkbh();
        String taskId= param.getTaskId();
        //double dkmj = param.getDkmj();
        String msg = String.format("--->submitOverlayCustomAnalyseEx start, analyseType: %s, jobid: %s, dkbh: %s",analyseType, jobId, dkbh);
        System.out.println(msg);
        logger.info(msg);

        CustomOverlay result = new CustomOverlay();
        result.setTaskId(taskId);
        result.setDkbh(dkbh);
        result.setJobId(jobId);
        result.setDkmj(param.getDkmj());
        result.setNf(param.getDlhynf());//数据年份

        int wkid = param.getWkid();
        Map<String, Map<String, Statis03Result>> overlays_statis = new HashMap<String, Map<String,Statis03Result>>();
        Map<String, List<DetailResult>> overlays_details = new HashMap<String, List<DetailResult>>();

        //核心代码，构建Java的多线程计算完成服务
        int sizeOfAnalyseTable = analyseTables.size();//待分析目标数据表的数量
        int maxThreadTaskSize = sizeOfAnalyseTable * 2 + 1;
        int keepAliveTime = 3000;

        BlockingDeque threadDeque= new LinkedBlockingDeque();
        ThreadPoolExecutor threadPool = new ThreadPoolExecutor(sizeOfAnalyseTable,
                maxThreadTaskSize,
                keepAliveTime,
                TimeUnit.MILLISECONDS,
                threadDeque);
        CompletionService<TaskResult> completionService = new ExecutorCompletionService<TaskResult>(threadPool);

        // 构建N个生成者
        // 提交线程并行处理，整合Executor和BlockingQueue的功能
        // ExecutorService threadPool = Executors.newCachedThreadPool();
        // ExecutorService threadPool = Executors.newFixedThreadPool(maxThreadTaskSize);
        //CompletionService<TaskResult> completionService = new ExecutorCompletionService<TaskResult>(threadPool);

        //逐个数据类型表AnalyseTable，提交线程分析
        int sizeOfSubmmitThread=0;
        Iterator<AnalyseTable> analyseTableIterator = analyseTables.iterator();
        while(analyseTableIterator.hasNext()) {
            AnalyseTable analyseTable = analyseTableIterator.next();

            System.out.println();

            //数据库表名
            String tableName = analyseTable.getTableName();//数据库的数据表表名
            String tableLabel = analyseTable.getTableLabel();
            String analysePointCode = analyseTable.getAnalysePoint().toLowerCase();//dltb、STBHHX、YJJBNT
            String typepoint = analyseTable.getTypepoint();//py、py2
            String dbKey = analyseTable.getDbKey();//sde、pg
            int fgeo_wkid = analyseTable.getWkid();//投影坐标EPSG代码
            int mbsjnf = param.getDlhynf();//目标数据年份

            System.out.println(String.format("--->submit processor, analysePoint: %s, tableName: %s, mbsjnf: %d ",analysePointCode, tableName, mbsjnf));


            //核心参数
            String dar1[] = analysePointCode.split("_");
            if( dar1.length >1 ){
                analysePointCode = dar1[1];//分析点
            }

            //2023-12-18 wangq
            //通过analystpoint匹配到对应的Processor处理器中
            String processorName = analysePointCode;
            List<AnalysePoint> analysePoints = analyseConfig.getAnalysePoints();
            for (AnalysePoint analysePoint: analysePoints) {
                if(analysePoint.getCode().equalsIgnoreCase(analysePointCode)){
                    processorName = analysePoint.getProcessor();
                    break;
                }
            }

            AnalyseTaskParam taskParam = new AnalyseTaskParam(param, typepoint, tableName);
            taskParam.setAnalystType(analyseType);
            taskParam.setDlhynf(mbsjnf);
            taskParam.setFgeo_wkid(fgeo_wkid);//设置目标图层的wkid
            taskParam.setDbKey(dbKey); //目标图层所在db
            taskParam.setAnalysePoint(analysePointCode);
            taskParam.setProcessName(processorName);

            AnalyseTaskProcessor taskProcessor = null;
            if("dltb".equals(processorName)) {
                if(param.getDlhynf()==0){
                    mbsjnf = StringUtil.parseInt(analyseTable.getYear(),"2021");//目标数据年份字符串
                    taskParam.setDlhynf(mbsjnf);//数据年份
                }
                taskProcessor = new DltbAnalyseTaskProcessor(taskParam,this.analyseConfig);
            }else if("yjjbnt".equals(processorName)){
                taskProcessor = new YjjbntAnalyseTaskProcessor(taskParam,this.analyseConfig);
            }else if("stbhhx".equals(processorName)){
                taskProcessor = new StbhhxAnalyseTaskProcessor(taskParam,this.analyseConfig);
            } else if("czkfbj".equals(processorName)){
                taskProcessor = new CzkfbjAnalyseTaskProcessor(taskParam,this.analyseConfig);
            } else if("tdghdl".equals(processorName)){
                taskProcessor = new TdghdlAnalyseTaskProcessor(taskParam,this.analyseConfig);
            } else if("jsydgzq".equals(processorName)){
                taskProcessor = new JsydgzqAnalyseTaskProcessor(taskParam,this.analyseConfig);
            } else if("csgh-kg".equals(processorName)){
                taskProcessor = new KgAnalyseTaskProcessor(taskParam,this.analyseConfig);
            } else if("cgjc".equals(processorName)){
                taskProcessor = new CgjcAnalyseTaskProcessor(taskParam,this.analyseConfig);
            }else if("common".equals(processorName)){
                taskProcessor = new CommonAnalyseTaskProcessor(taskParam,this.analyseConfig);
            }
            else {
                System.out.println("--->submitOverlayCustomAnalyseEx abandom, tableName is not fit to analsytPoint rules");
            }

            if(taskProcessor !=null) {
                //提交请求
                completionService.submit(taskProcessor);
                sizeOfSubmmitThread++;
            }
        }

        try {
            //主线程等待0.5秒
            Thread.sleep(500);
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }


        //利用主线程作为一个消费者
        for(int i=0; i<sizeOfSubmmitThread; i++) {
            try {
                //阻塞获取
                Future<TaskResult> ft = completionService.take();
                TaskResult taskResult = null;
                if(ft != null ) {
                    try {
                        //最长等待3秒
                        taskResult = ft.get(3000, TimeUnit.MILLISECONDS);
                        //taskResult = ft.get();
                    }
                    catch(InterruptedException e) {
                        e.printStackTrace();
                    }
                    catch (TimeoutException e) {
                        e.printStackTrace();
                    }

                    if(taskResult == null) {
                        continue;
                    }

                    this.threadAfterHandler(result, taskResult, overlays_statis, overlays_details );
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }
        }
        threadPool.shutdown();

        result.setOverlays_statis(overlays_statis);
        result.setOverlays_details(overlays_details);

        System.out.println(String.format("--->submitOverlayCustomAnalyseEx finished, analyseType: %s, jobid: %s, dkbh: %s",analyseType, jobId, dkbh));


        return result;
    }

    /**
     * 空间叠加套合分析，以不同图斑为单位开展多线程并行运算
     *
     * 项目红线分别与多年的变更调查（2009-2019）、规划地类、基本农田、管制区等进行空间叠加分析
     * @param analyseType 分析类型intersect/spatialquery
     * @param analyseTaskParamEx   地块任务集合
     * @return
     */
    public List<CustomOverlay> submitOverlayAnalyseByDK(String analyseType, List<AnalyseTaskParamEx> analyseTaskParamEx) {
        List<CustomOverlay> results = new ArrayList<CustomOverlay>();

        String msg = String.format("--->submitOverlayAnalyseByDK start, analyseType: %s",analyseType);
        System.out.println();
        System.out.println(msg);
        logger.info(msg);

        //核心代码，构建Java的多线程计算完成服务
        int numOfDkForAnalyseTask = analyseTaskParamEx.size();
        int maxThreadTaskSize= numOfDkForAnalyseTask * 2 + 1;

        // 构建N个生成者
        // 提交线程并行处理，整合Executor和BlockingQueue的功能
        ExecutorService threadPool = Executors.newCachedThreadPool();
        //ExecutorService threadPool = Executors.newFixedThreadPool(maxThreadTaskSize);
        CompletionService<TaskResult> completionService = new ExecutorCompletionService<TaskResult>(threadPool);

        //逐个数据类型表AnalyseTable，提交线程分析
        int xh=0;
        int sizeOfSubmmitThread=0;//提交的线程数
        Iterator<AnalyseTaskParamEx> taskParamIterator = analyseTaskParamEx.iterator();
        while(taskParamIterator.hasNext()) {
            AnalyseTaskParamEx analyseTaskParam = taskParamIterator.next();

            xh++; //序号

            AnalyseTable analyseTable = analyseTaskParam.getAnalyseTable();
            //数据库表名
            String tableName = analyseTable.getTableName();//数据库的数据表表名
            String tableLabel = analyseTable.getTableLabel();
            String analysePointCode = analyseTable.getAnalysePoint().toLowerCase();//dltb、STBHHX、YJJBNT...
            String typepoint = analyseTable.getTypepoint();//py、py2
            String dbKey = analyseTable.getDbKey();//sde/pg/sdo
            int fgeo_wkid = analyseTable.getWkid();//投影坐标EPSG代码


            String jobId = analyseTaskParam.getJobId();//任务编号,UUID
            String dkbh = analyseTaskParam.getDkbh();
            //double dkmj = param.getDkmj();
            System.out.println(String.format("--->xh: %d, jobId: %s, dkbh: %s, analysePoint: %s,tableName: %s ",xh, jobId, dkbh, analysePointCode,tableName));

            CustomOverlay result = new CustomOverlay();
            result.setTaskId(analyseTaskParam.getTaskId());
            result.setDkbh(dkbh);
            result.setJobId(analyseTaskParam.getJobId());
            result.setDkmj(analyseTaskParam.getDkmj());
            result.setNf(analyseTaskParam.getDlhynf());//数据年份

            int wkid = analyseTaskParam.getWkid();
            int mbsjnf = analyseTaskParam.getDlhynf();//目标数据年份

            //核心参数
            String dar1[] = analysePointCode.split("_");
            if( dar1.length >1 ){
                analysePointCode = dar1[1];//分析点
            }

            //2023-12-18 wangq
            //通过analystpoint匹配到对应的Processor处理器中
            String processorName = analysePointCode;
            List<AnalysePoint> analysePoints = analyseConfig.getAnalysePoints();
            for (AnalysePoint analysePoint: analysePoints) {
                if(analysePoint.getCode().equalsIgnoreCase(analysePointCode)){
                    processorName = analysePoint.getProcessor();
                    break;
                }
            }

            analyseTaskParam.setAnalystType(analyseType);//intersect/spatialquery/difference
            analyseTaskParam.setDlhynf(mbsjnf);//目标数据年份
            analyseTaskParam.setFgeo_wkid(fgeo_wkid);//设置目标图层的wkid
            analyseTaskParam.setTableName(tableName);//数据库表名
            analyseTaskParam.setFeaTypePoint(typepoint);//py/py2
            analyseTaskParam.setDbKey(dbKey); //目标图层所在db
            analyseTaskParam.setAnalysePoint(analysePointCode);//分析点：dltb、yjjbnt、stbhhx...
            analyseTaskParam.setProcessName(processorName);//processor处理器名称

            AnalyseTaskProcessor taskProcessor = null;
            if("dltb".equals(processorName)) {
                if(analyseTaskParam.getDlhynf()==0){
                    mbsjnf = StringUtil.parseInt(analyseTable.getYear(),"2021");//目标数据年份字符串
                    analyseTaskParam.setDlhynf(mbsjnf);//数据年份
                }
                //taskProcessor = new DltbAnalyseTaskProcessor(analyseTaskParam,this.analyseConfig);

                taskProcessor = new DltbAnalyseTaskProcessorEx(analyseTaskParam,this.analyseConfig);
            }else if("yjjbnt".equals(processorName)){
                taskProcessor = new YjjbntAnalyseTaskProcessor(analyseTaskParam,this.analyseConfig);
            }else if("stbhhx".equals(processorName)){
                taskProcessor = new StbhhxAnalyseTaskProcessor(analyseTaskParam,this.analyseConfig);
            } else if("czkfbj".equals(processorName)){
                taskProcessor = new CzkfbjAnalyseTaskProcessor(analyseTaskParam,this.analyseConfig);
            } else if("tdghdl".equals(processorName)){
                taskProcessor = new TdghdlAnalyseTaskProcessor(analyseTaskParam,this.analyseConfig);
            } else if("jsydgzq".equals(processorName)){
                taskProcessor = new JsydgzqAnalyseTaskProcessor(analyseTaskParam,this.analyseConfig);
            } else if("csgh-kg".equals(processorName)){
                taskProcessor = new KgAnalyseTaskProcessor(analyseTaskParam,this.analyseConfig);
            } else if("cgjc".equals(processorName)){
                taskProcessor = new CgjcAnalyseTaskProcessor(analyseTaskParam,this.analyseConfig);
            }
            else {
                System.out.println("--->submitOverlayAnalyseByDK abandom, tableName is not fit to analsytPoint rules");
            }

            if(taskProcessor !=null) {
                //提交请求
                completionService.submit(taskProcessor);
                sizeOfSubmmitThread++;
            }
        }

        try {
            //主线程等待0.5秒
            Thread.sleep(500);
        } catch (InterruptedException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }


        int sizeOfTaskFinished=0;//任务完成数

        //利用主线程作为一个消费者
        do{
            try {
                Future<TaskResult> ft = completionService.take();
                TaskResult taskResult = null;
                if(ft != null ) {
                    try {
                        //最长等待3秒
                        taskResult = ft.get(3000, TimeUnit.MILLISECONDS);
                        //res = ft.get();
                    }
                    catch(InterruptedException e) {
                        e.printStackTrace();
                    }
                    catch (TimeoutException e) {
                        e.printStackTrace();
                    }

                    if(taskResult == null) {
                        continue;
                    }
                    //保存分析结果
                    CustomOverlay result = this.threadAfterHandlerEx(taskResult);
                    results.add(result);
                    sizeOfTaskFinished++;
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            } catch (ExecutionException e) {
                e.printStackTrace();
            }

        }while( sizeOfTaskFinished < sizeOfSubmmitThread);

        threadPool.shutdown();
        System.out.println(String.format("--->submitOverlayAnalyseByDK finished, analyseType: %s",analyseType));

        return results;
    }

    /**
     * 空间叠加套合分析的后处理工作
     *
     * @param result
     * @param taskResult
     * @param overlays_statis
     * @param overlays_details
     */
    private void threadAfterHandler(CustomOverlay result, TaskResult taskResult, Map<String, Map<String, Statis03Result>> overlays_statis, Map<String, List<DetailResult>> overlays_details) {
        //获取打印线程处理信息
        String threadId= taskResult.getThreadId();
        String jobId = taskResult.getJobId();
        String taskId = taskResult.getTaskId();
        String analystPoint = taskResult.getAnalystPoint();
        String processorName= taskResult.getProcessorName();
        String tableName = taskResult.getTableName();
        String dkbh = taskResult.getDkbh();
        double dkmj=taskResult.getDkmj();
        String msgStr = String.format("一个任务完成 ,  threadId: %s, jobId: %s, taskId: %s, analystPoint: %s,tableName: %s, dkbh: %s ,dkmj: %f ",
                threadId,jobId,taskId,analystPoint,tableName,dkbh,dkmj);
        System.out.println();
        System.out.println(msgStr);

        //后台分析结果解析
        result.setDkmj(dkmj);//地块面积
        String key = analystPoint+"-"+tableName;
        String dar[] = analystPoint.split("_");
        if( dar.length>1 ){
            analystPoint = dar[1];
        }

        switch(analystPoint.toLowerCase()) {
        //switch(processorName.toLowerCase()) {
            case "dltb": {
                //土地利用现状-地类图斑
                List<DetailResult> detailResultList = new ArrayList<DetailResult>();

                Map<String, Statis03Result> dltb03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();
                List<DltbDetailResult> dltbDetailResultList = (List<DltbDetailResult>) taskResult.getDetailsListResult();//获取详细结果
                for (DltbDetailResult dltbDetailResult : dltbDetailResultList) {
                    DetailResult detailResult = dltbDetailResult;

                    try {
                        String geomStr = dltbDetailResult.getGeomText();
                        //System.out.println("dltb detail geomStr: "+geomStr);

                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detailResult.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailResultList.add(detailResult);
                }
                overlays_statis.put(key, dltb03StatisResultMap);
                overlays_details.put(key, detailResultList);

                break;
            }
            case "tdghdl": {
                //土地规划地类
                Map<String, Statis03Result> ghdl03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();

                List<GhdlDetailResult> tdghdlDetailList = (List<GhdlDetailResult>) taskResult.getDetailsListResult();
                List<DetailResult> detailList = new ArrayList<DetailResult>();
                for (GhdlDetailResult ghdl : tdghdlDetailList) {
                    DetailResult detail = new DetailResult();

                    detail.setBsm(ghdl.getBsm());
                    detail.setArea(ghdl.getGhdlmj());
                    detail.setTbbh(ghdl.getTbbh());
                    detail.setGeomText(ghdl.getGeomText());
                    detail.setBm(ghdl.getBm());
                    detail.setMc(ghdl.getMc());

                    try {
                        String geomStr = ghdl.getGeomText();
                        //System.out.println("dltb detail geomStr: "+geomStr);
                        if( !StringUtil.isNullOrEmpty(geomStr)) {
                            String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                            List<String> wktList = new ArrayList<String>();
                            wktList.add(wkt);
                            String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                            String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                            detail.setGeojson(geojson);
                        }
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailList.add(detail);
                }
                overlays_statis.put(key, ghdl03StatisResultMap);
                overlays_details.put(key, detailList);
                break;
            }
            case "jsydgzq": {
                //建设用地管制区
                Map<String, Statis03Result> jsydgzq03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();
                List<JsydgzqDetailResult> tdghdlDetailList = (List<JsydgzqDetailResult>) taskResult.getDetailsListResult();
                List<DetailResult> detailList = new ArrayList<DetailResult>();
                for (JsydgzqDetailResult jsydgzq : tdghdlDetailList) {
                    DetailResult detail = new DetailResult();

                    detail.setBsm(jsydgzq.getBsm());
                    detail.setArea(jsydgzq.getGzqmj());
                    detail.setTbbh(jsydgzq.getTbbh());
                    detail.setGeomText(jsydgzq.getGeomText());
                    detail.setBm(jsydgzq.getBm());
                    detail.setMc(jsydgzq.getMc());

                    try {
                        String geomStr = jsydgzq.getGeomText();
                        //System.out.println("dltb detail geomStr: "+geomStr);
                        if( !StringUtil.isNullOrEmpty(geomStr)) {
                            String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                            List<String> wktList = new ArrayList<String>();
                            wktList.add(wkt);
                            String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                            String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                            detail.setGeojson(geojson);
                        }
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailList.add(detail);
                }
                overlays_statis.put(key, jsydgzq03StatisResultMap);
                overlays_details.put(key, detailList);
                break;
            }
            case "yjjbnt": {
                //永久基本农田
                Map<String, Statis03Result> yjjbnt03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();
                List<YjjbntDetailResult> yjjbntDetailList = (List<YjjbntDetailResult>) taskResult.getDetailsListResult();
                List<DetailResult> detailList = new ArrayList<DetailResult>();
                for (YjjbntDetailResult yjjbnt : yjjbntDetailList) {
                    DetailResult detail = new DetailResult();

                    detail.setBsm(yjjbnt.getBsm());
                    detail.setArea(yjjbnt.getArea());
                    detail.setTbbh(yjjbnt.getTbbh());
                    detail.setBm(yjjbnt.getDlbm());
                    detail.setMc(yjjbnt.getMc());
                    detail.setGeomText(yjjbnt.getGeomText());

                    try {
                        String geomStr = yjjbnt.getGeomText();
                        //System.out.println("dltb detail geomStr: "+geomStr);

                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detail.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailList.add(detail);
                }
                overlays_details.put(key, detailList);
                overlays_statis.put(key, yjjbnt03StatisResultMap);

                break;
            }
            case "stbhhx": {
                //生态保护红线
                Map<String, Statis03Result> stbhhx03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();
                List<StbhhxDetailResult> stbhhxDetailList = (List<StbhhxDetailResult>) taskResult.getDetailsListResult();

                List<DetailResult> detailList = new ArrayList<DetailResult>();
                for (StbhhxDetailResult stbhhx : stbhhxDetailList) {
                    DetailResult detail = new DetailResult();
                    //图形geom
                    String geomStr = stbhhx.getGeomText();
                    detail.setArea(stbhhx.getArea());
                    detail.setTbbh(stbhhx.getTbbh());
                    detail.setBm(stbhhx.getLxbm());
                    detail.setMc(stbhhx.getHxlx());
                    detail.setGeomText(geomStr);
                    detail.setBsm(stbhhx.getBsm());
                    try {
                        //System.out.println("dltb detail geomStr: "+geomStr);
                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detail.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailList.add(detail);
                }
                overlays_details.put(key, detailList);
                overlays_statis.put(key, stbhhx03StatisResultMap);
                break;
            }

            case "czkfbj": {
                //城镇开发边界
                Map<String, Statis03Result> czkfbj03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();
                List<CzkfbjDetailResult> czkfbjDetailList = (List<CzkfbjDetailResult>) taskResult.getDetailsListResult();

                List<DetailResult> detailList = new ArrayList<DetailResult>();
                for (CzkfbjDetailResult czkfbj : czkfbjDetailList) {
                    DetailResult detail = new DetailResult();
                    //图形geom
                    String geomStr = czkfbj.getGeomText();
                    detail.setArea(czkfbj.getArea());
                    detail.setTbbh(czkfbj.getTbbh());
                    detail.setBm(czkfbj.getGhfqdm());
                    detail.setMc(czkfbj.getGhfqmc());
                    detail.setGeomText(geomStr);
                    detail.setBsm(czkfbj.getBsm());
                    try {
                        //System.out.println("dltb detail geomStr: "+geomStr);
                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detail.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailList.add(detail);
                }
                overlays_details.put(key, detailList);
                overlays_statis.put(key, czkfbj03StatisResultMap);
                break;
            }

            case "csgh-kg": {
                //控规
                Map<String, Statis03Result> stbhhx03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();
                List<KgDetailResult> kgDetailList = (List<KgDetailResult>) taskResult.getDetailsListResult();

                List<DetailResult> detailList = new ArrayList<DetailResult>();
                for (KgDetailResult kgDetail: kgDetailList) {
                    DetailResult detail = new DetailResult();
                    //图形geom
                    String geomStr = kgDetail.getGeomText();
                    detail.setArea(kgDetail.getArea());
                    detail.setTbbh(kgDetail.getTbbh());
                    detail.setBm(kgDetail.getKgfldm());
                    detail.setMc(kgDetail.getKgflmc());
                    detail.setGeomText(geomStr);
                    detail.setBsm(kgDetail.getBsm());
                    try {
                        //System.out.println("dltb detail geomStr: "+geomStr);
                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detail.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailList.add(detail);
                }
                overlays_details.put(key, detailList);
                overlays_statis.put(key, stbhhx03StatisResultMap);
                break;
            }

            case "cgjc": {
                //常规监测图斑
                List<DetailResult> detailList = (List<DetailResult>) taskResult.getDetailsListResult();
                for (DetailResult detailResult: detailList) {

                    //图形geom
                    String geomStr = detailResult.getGeomText();

                    try {
                        //geomTxt转换位geojson
                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detailResult.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }
                overlays_details.put(key, detailList);

                break;
            }
            case "common": {
                //通用数据
                List<DetailResult> detailList = (List<DetailResult>) taskResult.getDetailsListResult();
                for (DetailResult detailResult: detailList) {

                    //图形geom
                    String geomStr = detailResult.getGeomText();

                    try {
                        //geomTxt转换位geojson
                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detailResult.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }

                overlays_details.put(key, detailList);

                break;
            }
        }
    }

    private CustomOverlay threadAfterHandlerEx(  TaskResult taskResult) {

        //获取打印线程处理信息
        String threadId= taskResult.getThreadId();
        String jobId = taskResult.getJobId();
        String taskId = taskResult.getTaskId();
        String analystPoint = taskResult.getAnalystPoint();
        String processorName = taskResult.getProcessorName();
        String tableName = taskResult.getTableName();
        String dkbh = taskResult.getDkbh();
        double dkmj=taskResult.getDkmj();
        String msgStr = String.format("一个任务完成 ,  threadId: %s, jobId: %s, taskId: %s, analystPoint: %s,tableName: %s, dkbh: %s ,dkmj: %f ",
                threadId,jobId,taskId,analystPoint,tableName,dkbh,dkmj);
        System.out.println();
        System.out.println(msgStr);

        //分析结果
        CustomOverlay result= new CustomOverlay();
        Map<String, Map<String, Statis03Result>> overlays_statis = new HashMap<String, Map<String, Statis03Result>>();
        Map<String, List<DetailResult>> overlays_details = new HashMap<String, List<DetailResult>>();

        //后台执行状态
        boolean bAnalystStatus = taskResult.isbAnalystStatus();
        result.setbSuccessed(bAnalystStatus);
        if (bAnalystStatus==false){
            result.setIssueMessage(taskResult.getMessage());
        }

        //后台分析结果解析
        result.setDkmj(dkmj);//地块面积
        String key = analystPoint+"-"+tableName;
        String dar[] = analystPoint.split("_");
        if( dar.length>1 ){
            analystPoint = dar[1];
        }
        switch(analystPoint.toLowerCase()) {
        //switch(processorName.toLowerCase()) {
            case "dltb": {
                //土地利用现状-地类图斑
                List<DetailResult> detailResultList = new ArrayList<DetailResult>();

                Map<String, Statis03Result> dltb03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();
                List<DltbDetailResult> dltbDetailResultList = (List<DltbDetailResult>) taskResult.getDetailsListResult();//获取详细结果
                for (DltbDetailResult dltbDetailResult : dltbDetailResultList) {
                    DetailResult detailResult = dltbDetailResult;

                    try {
                        String geomStr = dltbDetailResult.getGeomText();
                        //System.out.println("dltb detail geomStr: "+geomStr);

                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detailResult.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailResultList.add(detailResult);
                }
                overlays_statis.put(key, dltb03StatisResultMap);
                overlays_details.put(key, detailResultList);

                break;
            }
            case "tdghdl": {
                //土地规划地类
                Map<String, Statis03Result> ghdl03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();

                List<GhdlDetailResult> tdghdlDetailList = (List<GhdlDetailResult>) taskResult.getDetailsListResult();
                List<DetailResult> detailList = new ArrayList<DetailResult>();
                for (GhdlDetailResult ghdl : tdghdlDetailList) {
                    DetailResult detail = new DetailResult();

                    detail.setBsm(ghdl.getBsm());
                    detail.setArea(ghdl.getGhdlmj());
                    detail.setTbbh(ghdl.getTbbh());
                    detail.setGeomText(ghdl.getGeomText());
                    detail.setBm(ghdl.getBm());
                    detail.setMc(ghdl.getMc());

                    try {
                        String geomStr = ghdl.getGeomText();
                        //System.out.println("dltb detail geomStr: "+geomStr);
                        if( !StringUtil.isNullOrEmpty(geomStr)) {
                            String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                            List<String> wktList = new ArrayList<String>();
                            wktList.add(wkt);
                            String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                            String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                            detail.setGeojson(geojson);
                        }
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailList.add(detail);
                }
                overlays_statis.put(key, ghdl03StatisResultMap);
                overlays_details.put(key, detailList);
                break;
            }
            case "jsydgzq": {
                //建设用地管制区
                Map<String, Statis03Result> jsydgzq03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();
                List<JsydgzqDetailResult> tdghdlDetailList = (List<JsydgzqDetailResult>) taskResult.getDetailsListResult();
                List<DetailResult> detailList = new ArrayList<DetailResult>();
                for (JsydgzqDetailResult jsydgzq : tdghdlDetailList) {
                    DetailResult detail = new DetailResult();

                    detail.setBsm(jsydgzq.getBsm());
                    detail.setArea(jsydgzq.getGzqmj());
                    detail.setTbbh(jsydgzq.getTbbh());
                    detail.setGeomText(jsydgzq.getGeomText());
                    detail.setBm(jsydgzq.getBm());
                    detail.setMc(jsydgzq.getMc());

                    try {
                        String geomStr = jsydgzq.getGeomText();
                        //System.out.println("dltb detail geomStr: "+geomStr);
                        if( !StringUtil.isNullOrEmpty(geomStr)) {
                            String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                            List<String> wktList = new ArrayList<String>();
                            wktList.add(wkt);
                            String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                            String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                            detail.setGeojson(geojson);
                        }
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailList.add(detail);
                }
                overlays_statis.put(key, jsydgzq03StatisResultMap);
                overlays_details.put(key, detailList);
                break;
            }
            case "yjjbnt": {
                //永久基本农田
                Map<String, Statis03Result> yjjbnt03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();
                List<YjjbntDetailResult> yjjbntDetailList = (List<YjjbntDetailResult>) taskResult.getDetailsListResult();
                List<DetailResult> detailList = new ArrayList<DetailResult>();
                for (YjjbntDetailResult yjjbnt : yjjbntDetailList) {
                    DetailResult detail = new DetailResult();

                    detail.setBsm(yjjbnt.getBsm());
                    detail.setArea(yjjbnt.getArea());
                    detail.setTbbh(yjjbnt.getTbbh());
                    detail.setBm(yjjbnt.getDlbm());
                    detail.setMc(yjjbnt.getMc());
                    detail.setGeomText(yjjbnt.getGeomText());

                    try {
                        String geomStr = yjjbnt.getGeomText();
                        //System.out.println("dltb detail geomStr: "+geomStr);

                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detail.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailList.add(detail);
                }
                overlays_details.put(key, detailList);
                overlays_statis.put(key, yjjbnt03StatisResultMap);

                break;
            }
            case "stbhhx": {
                //生态保护红线
                Map<String, Statis03Result> stbhhx03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();
                List<StbhhxDetailResult> stbhhxDetailList = (List<StbhhxDetailResult>) taskResult.getDetailsListResult();

                List<DetailResult> detailList = new ArrayList<DetailResult>();
                for (StbhhxDetailResult stbhhx : stbhhxDetailList) {
                    DetailResult detail = new DetailResult();
                    //图形geom
                    String geomStr = stbhhx.getGeomText();
                    detail.setArea(stbhhx.getArea());
                    detail.setTbbh(stbhhx.getTbbh());
                    detail.setBm(stbhhx.getLxbm());
                    detail.setMc(stbhhx.getHxlx());
                    detail.setGeomText(geomStr);
                    detail.setBsm(stbhhx.getBsm());
                    try {
                        //System.out.println("dltb detail geomStr: "+geomStr);
                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detail.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailList.add(detail);
                }
                overlays_details.put(key, detailList);
                overlays_statis.put(key, stbhhx03StatisResultMap);
                break;
            }

            case "czkfbj": {
                //城镇开发边界
                Map<String, Statis03Result> czkfbj03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();
                List<CzkfbjDetailResult> czkfbjDetailList = (List<CzkfbjDetailResult>) taskResult.getDetailsListResult();

                List<DetailResult> detailList = new ArrayList<DetailResult>();
                for (CzkfbjDetailResult czkfbj : czkfbjDetailList) {
                    DetailResult detail = new DetailResult();
                    //图形geom
                    String geomStr = czkfbj.getGeomText();
                    detail.setArea(czkfbj.getArea());
                    detail.setTbbh(czkfbj.getTbbh());
                    detail.setBm(czkfbj.getGhfqdm());
                    detail.setMc(czkfbj.getGhfqmc());
                    detail.setGeomText(geomStr);
                    detail.setBsm(czkfbj.getBsm());
                    try {
                        //System.out.println("dltb detail geomStr: "+geomStr);
                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detail.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailList.add(detail);
                }
                overlays_details.put(key, detailList);
                overlays_statis.put(key, czkfbj03StatisResultMap);
                break;
            }

            case "csgh-kg": {
                //控规
                Map<String, Statis03Result> stbhhx03StatisResultMap = (Map<String, Statis03Result>) taskResult.getSummary03Result();
                List<KgDetailResult> kgDetailList = (List<KgDetailResult>) taskResult.getDetailsListResult();

                List<DetailResult> detailList = new ArrayList<DetailResult>();
                for (KgDetailResult kgDetail: kgDetailList) {
                    DetailResult detail = new DetailResult();
                    //图形geom
                    String geomStr = kgDetail.getGeomText();
                    detail.setArea(kgDetail.getArea());
                    detail.setTbbh(kgDetail.getTbbh());
                    detail.setBm(kgDetail.getKgfldm());
                    detail.setMc(kgDetail.getKgflmc());
                    detail.setGeomText(geomStr);
                    detail.setBsm(kgDetail.getBsm());
                    try {
                        //System.out.println("dltb detail geomStr: "+geomStr);
                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detail.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }

                    detailList.add(detail);
                }
                overlays_details.put(key, detailList);
                overlays_statis.put(key, stbhhx03StatisResultMap);
                break;
            }

            case "cgjc": {
                //常规监测图斑
                List<DetailResult> detailList = (List<DetailResult>) taskResult.getDetailsListResult();
                for (DetailResult detailResult: detailList) {

                    //图形geom
                    String geomStr = detailResult.getGeomText();

                    try {
                        //geomTxt转换位geojson
                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detailResult.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }
                overlays_details.put(key, detailList);

                break;
            }

            case "common": {
                //通用数据分析，只保留叠加后的详细数据
                List<DetailResult> detailList = (List<DetailResult>) taskResult.getDetailsListResult();
                for (DetailResult detailResult: detailList) {

                    //图形geom
                    String geomStr = detailResult.getGeomText();

                    try {
                        //geomTxt转换位geojson
                        String wkt = JTSGeometryWKTUtil.geomStr2wkt(geomStr);
                        List<String> wktList = new ArrayList<String>();
                        wktList.add(wkt);
                        String geoType = JTSGeometryWKTUtil.getGeomType(geomStr);
                        String geojson = JTSGeometryWKTUtil.wkt2GeoJson(wktList, geoType);

                        detailResult.setGeojson(geojson);
                    }catch (Exception ex){
                        ex.printStackTrace();
                    }
                }

                overlays_details.put(key, detailList);

                break;
            }
        }

        result.setOverlays_statis(overlays_statis);
        result.setOverlays_details(overlays_details);

        return result;
    }

}
